package com.salton123.soulove.sailfish.video.ui.adapter;

import android.graphics.Rect;
import android.view.View;

import com.salton123.soulove.sailfish.entity.AlbumMultiTypeEntity;
import com.salton123.soulove.sailfish.entity.IMultiType;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import static com.salton123.soulove.sailfish.entity.MultiTypeEntityKt.MULTI_TYPE_ALBUM;
import static com.salton123.soulove.sailfish.entity.MultiTypeEntityKt.VIEW_TYPE_LEFT;

/**
 * User: newSalton@outlook.com
 * Date: 2019/9/9 16:16
 * ModifyTime: 16:16
 * Description:
 */
public class SplitItemDecoration extends RecyclerView.ItemDecoration {
    List<IMultiType> mDatas;
    private final int space;

    public SplitItemDecoration(int space, List<IMultiType> datas) {
        this.space = space;
        this.mDatas = datas;
    }

    @Override
    public void getItemOffsets(
        @NonNull Rect outRect, @NonNull View view,
        @NonNull RecyclerView parent,
        @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int position = parent.getChildAdapterPosition(view);
        if (mDatas != null && mDatas.size() > 0) {
            IMultiType iDailyType = mDatas.get(position);
            if (iDailyType.getType() == MULTI_TYPE_ALBUM) {
                AlbumMultiTypeEntity dailyTypeContent = (AlbumMultiTypeEntity) iDailyType;
                if (dailyTypeContent.getViewType() == VIEW_TYPE_LEFT) {
                    outRect.left = space;
                    outRect.right = space / 2;
                } else {
                    outRect.left = space / 2;
                    outRect.right = space;
                }
                // 行间距
                if (position >= 2) {
                    outRect.top = space;
                }
            } else {
                outRect.left = space / 2;
                outRect.right = space / 2;
            }
            if (position == 0) {
                outRect.top = space;
            }
        }
    }
}
